package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.Remote;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.OPSettlementDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.OPSettlementTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.OPSettlementServiceInt;

/**
 * Session Bean implementation class OPSettlementService
 */
@Stateless
@Remote({ OPSettlementServiceInt.class })
public class OPSettlementService implements OPSettlementServiceInt {

	@EJB
	private OPSettlementDAOInt opSettlementDao;

	/**
	 * Default constructor.
	 */
	public OPSettlementService() {
	}

	@Override
	public int createOPSettlementCode(String label, String description,
			float factor /* int settlementClass */) throws RuntimeException {
		OPSettlementTBL newItem = new OPSettlementTBL();

		newItem.setCode_label(label);
		newItem.setDescription(description);
		newItem.setFactor(factor);
		// newItem.setSettlement_class(settlementClass);

		opSettlementDao.persist(newItem);

		return DONE;
	}

	@Override
	public int deleteOPSettlementCode(String codeLabel) throws RuntimeException {
		opSettlementDao.delete(codeLabel);
		return DONE;
	}

	@Override
	public List<OPSettlementTBL> getAvailableOPSettlementCode() {
		List<OPSettlementTBL> resultList = opSettlementDao
				.getAvailableOPSettlementCode();

		return resultList;
	}

	@Override
	public OPSettlementTBL getOPSettlementCode(String codeLabel) {
		return this.opSettlementDao.retrieveOPSettlementCodeByID(codeLabel);
	}

	@Override
	public void updateSettlementCode(OPSettlementTBL opSettlementTBL) {
		this.opSettlementDao.update(opSettlementTBL);

	}

	@Override
	public List<OPSettlementTBL> getOPSettlementCodeByClass(int settlement_class) {
		return this.opSettlementDao
				.getAvailableOPSettlementCodeByClass(settlement_class);
	}

}
